* static and dynamic allocation results

set more off
capture log close
clear
** version 14.0 necessary for putexcel
version 14.0

//load global vars
cd "/disk/agedisk3/medicare.work/chandra-DUA52080/pragya-dua52080/replication/"

log using covariance.log, replace

******** Exports standard deviation and correlation / covariance
foreach yidx in 1 4{
		
		estimates use  Exportable_Results/estimates/longsurvrs_ami100_yidx`yidx'_a.ster

		_diparm lns1_1_1, f(exp(@)) d(exp(@))
		local std_dev_cons`yidx' = r(est)
		local std_dev_cons`yidx' = `std_dev_cons`yidx''*100
		
		_diparm lns1_1_3, f(exp(@)) d(exp(@))
		local std_dev_b`yidx' = r(est)
		local std_dev_b`yidx' = `std_dev_b`yidx''*100
		
		_diparm atr1_1_1_3, f(tanh(@)) d(1-tanh(@)^2)
		local corr_b_cons`yidx' = r(est)
		
		local corr_b_w_alt`yidx' = (`std_dev_b`yidx''^2+`corr_b_cons`yidx''*`std_dev_b`yidx''*`std_dev_cons`yidx'')/((`std_dev_b`yidx''^2+`std_dev_cons`yidx''^2+2*`corr_b_cons`yidx''*`std_dev_b`yidx''*`std_dev_cons`yidx'')^0.5*`std_dev_b`yidx'')
 		
}

** Exports results **
capture noisily mkdir Exportable_Results/Appendix_Table5/ 
putexcel A2=("Standard deviation of performance for white patients") A3 = ("Standard deviation of Black-white performance differential") A4 = ("Correlation between performance for white patients and Black-white differential") A5 = ("Correlation between performance for white patients and Black patients") B1 =("Baseline") C1 =("Endline") B2 =("`std_dev_b1'")  B3 =("`std_dev_cons1'") B4 = ("`corr_b_cons1'") B5 = ("`corr_b_w_alt1'")   C2 =("`std_dev_b4'")  C3 =("`std_dev_cons4'") C4 = ("`corr_b_cons4'") C5 = ("`corr_b_w_alt4'") using   Exportable_Results/Appendix_Table5/Appendix_Table5.xlsx, replace             



log close
